<?php
mb_internal_encoding('UTF-8');
header('Content-Type: text/html; charset=UTF-8');

// translations
$lang['birthplace'] = "Syntymäpaikka";
$lang['eliteCoefficient'] = "Eliittikerroin";
$lang['eliteOMeter'] = "Eliittimittari";
$lang['howToInterpret'] = '<h2>Näin tulkitset halutuloksia</h2><p>Oranssilla merkitystä tietokannasta hakemaasi sukunimeä löytyy prosentuaalisesti eniten. Eliittimittari on kieli poskessa laskettu arvio siitä, miten elitistinen hakemasi sukunimi on. Eliittimittarin tuloksia voit verrata esimerkiksi <a href=\"http://www.iltalehti.fi/uutiset/200905299670952_uu.shtml\">Suomen rikkaimpien sukujen listaan</a>.</p>';
$lang['instruction'] = "Anna sukunimi (ja paina näppäimistön Enter-painiketta)";
$lang['newSearch'] = "Suorita uusi haku";
$lang['otherDatabases'] = "Muut tietokannat";
$lang['performingSearch'] = "Suoritetaan hakua... Odota hetki.";
$lang['search'] = "Hae!";
$lang['slogan'] = "mitä julkiset tietokannat kertovat sukunimestäsi?";
$lang['voteForUs'] = "Äänestä meitä Mindtrek 2009 -kisassa!";

if (isset($_GET['hl']) && $_GET['hl'] == "en")
{
    $lang['birthplace'] = "Place of birth";
    $lang['eliteCoefficient'] = "Elite coefficient";
    $lang['eliteOMeter'] = "Elite-o-meter";
    $lang['howToInterpret'] = '<h2>How to interpret the search results</h2><p>The database marked with orange features the highest percentage of the family name you are looking for. Elite-o-meter is a tongue-in-cheek estimate of how elitistic the family name is. You can compare elite-o-meter\'s results, for instance, to the <a href=\"http://www.iltalehti.fi/uutiset/200905299670952_uu.shtml\">list of the richest families in Finland</a>.</p>';
    $lang['instruction'] = "Type in the surname (and press Enter on your keyboard)";
    $lang['newSearch'] = "Perform a new search";
    $lang['otherDatabases'] = "Other databases";
    $lang['performingSearch'] = "Performing search... Wait a moment.";
    $lang['search'] = "Go!";
    $lang['slogan'] = "what do public databases in Finland say about your family name?";
    $lang['voteForUs'] = "Vote for us in the Mindtrek 2009 poll!";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<!-- Created by Tapio Nurminen and Jaakko Louhio, 2009 (www.tietokannat.fi) -->

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="description" content="Nomen est omen" />
<meta name="keywords" content="sukunimet, surnames" />

<title>Nomen est omen</title>
<script type="text/javascript" src="http://www.tietokannat.fi/shared_files/js/jquery.js"></script>
<script type="text/javascript">
/* <![CDATA[ */ 

    // creates elite bar
    function makeBar()
    {
        if (document.getElementById('elitefinaleduskunta') != null && document.getElementById('elitefinaleduskunta').innerHTML != ""
        && document.getElementById('elitefinalbiography') != null && document.getElementById('elitefinalbiography').innerHTML != ""
        && document.getElementById('elitefinalfallen') != null && document.getElementById('elitefinalfallen').innerHTML != ""
        && document.getElementById('elitefinalmatrikkeli') != null && document.getElementById('elitefinalmatrikkeli').innerHTML != ""
        && document.getElementById('elitefinalnames') != null && document.getElementById('elitefinalnames').innerHTML != ""
        && document.getElementById('elitefinalartist') != null && document.getElementById('elitefinalartist').innerHTML != ""
        )
        {
        
            var elitetotal =
            parseInt(document.getElementById('eliteartist').value)
            + parseInt(document.getElementById('elitebiography').value)
            + parseInt(document.getElementById('eliteeduskunta').value)
            + parseInt(document.getElementById('elitefallen').value)
            + parseInt(document.getElementById('elitematrikkeli').value)
            + parseInt(document.getElementById('elitenames').value)
            ;

            var percent = elitetotal / 50;
            
            if (percent > 100)
                percent = 100;
            
            var barColor = "indianred";
            if (percent >= 50)
                barColor = "green";
            
            document.getElementById('birthplace').innerHTML = "<h2><?php echo $lang['birthplace']; ?></h2><p>Nimeä on esiintynyt muun muassa alueella: " + document.getElementById('birthplacefallen').value + "</p>";
            document.getElementById('descr').innerHTML = "<?php echo $lang['howToInterpret']; ?>";
            document.getElementById('bar').innerHTML = "<h2><?php echo $lang['eliteOMeter']; ?></h2><p>" + percent + "%</p><br />";//"&nbsp;";
            document.getElementById('bar').setAttribute('style', 'width: ' + percent + '%; background-color:' + barColor + ';');
            document.getElementById('extrainfo').innerHTML = "<h2><?php echo $lang['otherDatabases']; ?></h2><p>Muita tietokantoja, joista voit hakea sukunimitietoja:</p><p>Suomen sukututkimusseuran Suomen hautausmaat -tietokanta<br /><a href=\"http://haudat.genealogia.fi/php/indexs.php\" target=\"_blank\">http://haudat.genealogia.fi/php/indexs.php</a></p><p>Arkistolaitoksen Suomen sotasurmat 1914–1922 -tietokanta<br /><a href=\"http://vesta.narc.fi/cgi-bin/db2www/sotasurmaetusivu/main\" target=\"_blank\">http://vesta.narc.fi/cgi-bin/db2www/sotasurmaetusivu/main</a></p>";
        }
    }

    function normalizeResult(divname)
    { 	
        if (document.getElementById('elite'+divname).value != 0)
        {
        	var normalizer = (parseInt(document.getElementById('countnames').value) * 1000) / (5336458 * 2);
        	var elite = parseInt(document.getElementById('elite'+divname).value / normalizer);
        	document.getElementById('elitefinal'+divname).innerHTML = "<?php echo $lang['eliteCoefficient']; ?>: " + elite;
        	document.getElementById('elite'+divname).value = elite;
        }
        else
        {
        	document.getElementById('elitefinal'+divname).innerHTML = "<?php echo $lang['eliteCoefficient']; ?>: 0";
        	document.getElementById('elite'+divname).value = 0;
        }
        makeBar();        
    }            
             
    function set_Cookie(name,value,path,domain,secure) {
        var expires = new Date();
        dtsec.setSeconds(dtsec.getSeconds()+(60*60*24*3));                 
    	document.cookie = name + "=" +escape(value) +
        ( (expires) ? ";expires=" + expires.toGMTString() : "") +
        ( (path) ? ";path=" + path : "") + 
        ( (domain) ? ";domain=" + domain : "") +
        ( (secure) ? ";secure" : "");
	}     
    
 	function highlightResult(divname)
 	{
		if(document.getElementById('percent'+divname).value >= document.getElementById('percenteduskunta').value
				&& document.getElementById('percent'+divname).value >= document.getElementById('percentnames').value
				&& document.getElementById('percent'+divname).value >= document.getElementById('percentfallen').value
				&& document.getElementById('percent'+divname).value >= document.getElementById('percentmatrikkeli').value
				&& document.getElementById('percent'+divname).value >= document.getElementById('percentbiography').value
				&& document.getElementById('percent'+divname).value >= document.getElementById('percentartist').value)
		{
			document.getElementById(divname).setAttribute('style', 'background-color:darksalmon;'); 			
		}
		else
		{
			document.getElementById(divname).setAttribute('style', '');
		}
 	}
 	function getRanksOfFallen()
 	{
 	}

    function checkResults()
    {
        if (document.getElementById('percenteduskunta') != null && document.getElementById('percentnames') != null
                && document.getElementById('percentfallen') != null && document.getElementById('percentmatrikkeli') != null
                && document.getElementById('percentbiography') != null && document.getElementById('percentartist') != null
                && document.getElementById('percentartist') != null
         )
        {
            highlightResult('eduskunta');
            highlightResult('names');
            highlightResult('fallen');
            highlightResult('matrikkeli');
            highlightResult('biography');
            highlightResult('artist');
            normalizeResult('eduskunta');
            normalizeResult('matrikkeli');
            normalizeResult('biography');
            normalizeResult('artist');
//            normalizeResult('names');

            get_mashup('ranks_of_fallen', document.getElementById("surname").value, 'Ladataan tietoja 1939-1945 sodissa kaatuneiden sotilasarvoista. Tämä kestää enimmillään noin minuutin.', false);
                                    
        }
    }
 
    function get_mashup(divname, name, loadtext, checkresults)
    {		        
        document.getElementById(divname).innerHTML = '<p>'+loadtext+' <img border="0" alt="" src="http://www.tietokannat.fi/shared_files/images/spinning.gif"/></p>';
    	$.post("mashup_interface.php", { type: divname, surname: name },
    	    	 function(data){ eval("document.getElementById('"+divname+"').innerHTML = data");    	
    	    	 	if(divname == 'ranks_of_fallen')
						eval("normalizeResult('fallen')");
        	    	else    	 	
						eval("checkResults()");
       	    	 });

    }
	function reset_div(divname)
	{
		document.getElementById(divname).innerHTML = "";
		document.getElementById(divname).setAttribute("style", "");
	}
    
    function mashups(){
        document.getElementById('newSearch').setAttribute('style', 'display:block;');
        document.getElementById('descr').setAttribute('style', 'display:block;');
        document.getElementById('descr').innerHTML = "<p><?php echo $lang['performingSearch']; ?></p>";

        var name = document.getElementById("surname").value;
        
//        name = unescape( encodeURIComponent(name));
       	reset_div("eduskunta");
       	reset_div("names");
       	reset_div("fallen");
       	reset_div("matrikkeli");
       	reset_div("biography");
       	reset_div("artist");
       	reset_div("bar");
       	reset_div("birthplace");
        get_mashup("eduskunta",name, "Ladataan tietoja eduskunnasta.", true);
        get_mashup("names", name, "Ladataan tietoja sukunimitietokannasta.", true);
        get_mashup("fallen", name, "Ladataan tietoja 1939-1945 sodissa kaatuneista.", true);
        get_mashup("matrikkeli", name, "Ladataan tietoja ylioppilasmatrikkelista.", true);
        get_mashup("biography", name, "Ladataan tietoja Kansallisbiografiasta.", true);
        get_mashup("artist", name, "Ladataan tietoja kuvataiteilijamatrikkelista.", true);        
    }
/* ]]> */ 
</script>

<style type="text/css">
* {
    margin: 0;
    padding: 0;
}
body {
    background-color: #fff;
    color: #333;
    font-family: verdana, arial, helvetica, sans-serif;
    font-size: 80%;
    text-align: left;
}
h1 {
    font: 48px "trebuchet ms",verdana, sans-serif;
}
h2 {
    margin-bottom: .5em;
}
input[type="text"] {
    -moz-background-clip:border;
    -moz-background-inline-policy:continuous;
    -moz-background-origin:padding;
    -moz-border-radius:5px;
    background:#FFF none repeat scroll 0 0;
    border-color:#EEE;
    border-style:solid;
    border-width:1px 0 1px 1px;
    font-family:Helvetica,Arial,Sans-serif;
    font-size:18px;
    font-size-adjust:none;
    font-stretch:normal;
    font-style:normal;
    font-variant:normal;
    font-weight:normal;
    line-height:normal;
    outline-width:0;
    padding:8px 10px;
    width:280px;
}
label {
    color:#585858;
    display:block;
    margin:0 0 2px 2px;
}
p {
    margin-bottom: 1em;
}

/* classes and id's */
.alert {
    background-color: white;
    padding: 1em;
}
#footer {
    border-top: 1px solid white;
    padding: 20px 10px;
}
#footer,
#header {
    background-color: #FFC0CB;
}
#header {
    padding: 30px 10px;
}
#results {
    border-top: 1px solid white;
    font-size: 90%;
    padding: 20px;
}
#results a {
    text-decoration: none;
}
#results form {
    margin-bottom: 1em;
}
#results div {
    margin: 20px 0;
}
#wrapper {
    background-color: #FFD0D8;
    margin: 0 auto;
    width: 860px;
}
#submitButton:hover,
#submitButton:focus {
    background-position:0 -5px;
    color:#111;
    cursor:pointer;
}
#submitButton {
    -moz-background-clip:border;
    -moz-background-inline-policy:continuous;
    -moz-background-origin:padding;
    -moz-border-radius-bottomright:5px;
    -moz-border-radius-topright:5px;
    background:#BBB url(search.png) repeat-x scroll 0 0;
    border:1px solid #EEE;
    color:#333;
    font-family:Helvetica,Arial,Sans-serif;
    font-size:18px;
    font-size-adjust:none;
    font-stretch:normal;
    font-style:normal;
    font-variant:normal;
    font-weight:bold;
    line-height:normal;
    margin-left:-0.5em;
    outline-color:-moz-use-text-color;
    outline-style:none;
    outline-width:medium;
    padding:8px 15px;
    text-decoration:none;
}
/* submit button styled as a link */
.submitB {
    border:none;
    font: 12px verdana, arial, helvetica, sans-serif;
    text-decoration:underline;
    color:blue;
    background-color:transparent;
    cursor:pointer;
} 
</style>

</head>

<?php 

echo
'<body>
<div id="wrapper">
<div id="header">
<div id="lang" style="text-align:right;"><a href="./nomen.php">Finnish</a>&nbsp;&nbsp;<a href="./nomen.php?hl=en">English</a></div>

<h1>Nomen est omen <sup style="color:red;font-size:50%;">Beta</sup></h1>
<div id="slogan" style="font-size:110%;margin-bottom:20px;">&ndash; '.$lang['slogan'].'</div>

<!--p style="background-color:white;border:1px solid red;font-size:11px;padding:1em;">Some of the remote databases not replying. Please check in again later.</p-->

<label for="surname">'.$lang['instruction'].'</label><br />
<input type="text" id="surname" tabindex="1" onkeypress="if (event.keyCode == 13) {mashups();}" />
<!--a id="submitButton" class="submit" tabindex="2" href="">'.$lang['search'].'</a-->
<p style="margin-top:2em;"><a href="http://www.mindtrek.org/2009/apps_for_democracy_poll">'.$lang['voteForUs'].'</a></p>
</div><!-- close header -->

<div id="results">
<div id="newSearch" style="display:none;"><a href="'.htmlentities($_SERVER['REQUEST_URI']).'" style="margin-left:1em;">'.$lang['newSearch'].'</a></div>
<div id="descr" class="alert" style="display:none;"></div>
<div class="bar" id="bar"></div>

<div id="names"></div>
<div id="birthplace"></div>
<div id="eduskunta"></div>
<div id="fallen"></div>
<div id="matrikkeli"></div>
<div id="biography"></div>
<div id="artist"></div>
<div id="extrainfo"></div>

</div><!-- close results -->

<div id="footer">
<p style="background-color:white;border:1px solid red;font-size:11px;padding:1em;">Please note that this is a very early Beta with lots of things to fix. Please send your feedback to tapio.nurminen AT tietokannat.fi. Thx!</p>
Mashup created by <a href="http://www.tietokannat.fi">Tapio Nurminen &amp; Jaakko Louhio</a> 2009.
</div>

</div><!-- close wrapper -->

</body>
</html>';

?>